<template>
  <div class="playlist-detail">
    <!-- 歌单介绍信息 -->
    <div class="playlist-info">
      <!-- 图片 -->
      <div class="pic">
        <img :src="album.picUrl + '?param=200y200'" alt />
      </div>
      <!-- 文字信息 -->
      <div class="info">
        <div class="title">
          <div class="icon-title">专辑</div>{{album.name }} <div class="transName">{{getTransName}}</div>
        </div>

        <!-- 按钮组件 -->
        <div class="btn-group">
          <el-button-group>
            <el-button @click="playnowMusiclist" size="medium" type="primary" round>
              <span class="iconfont icon-palyer-start-01"></span>播放全部
            </el-button>
            <el-button @click="addmusic" size="medium" type="primary" round><span class="el-icon-plus"></span>
            </el-button>
          </el-button-group>
        </div>
        <div class="time">时间：{{ getTime }}</div>
        <div class="author">
          歌手：<div @click="$router.push({ name: 'artistAccount', query: { id:album.artist.id } })" class="name">
            {{getArtistName}}</div>
        </div>

        <div class="input-search">
          <el-input v-model="search" size="mini" placeholder="输入关键字搜索" />
        </div>

      </div>
    </div>
    <!-- 歌单介绍信息结束 -->
    <!-- 歌曲列表 -->
    <div class="playlist-music">
      <el-tabs border="false" v-model="activeName" @tab-click="handleClick">
        <el-tab-pane class="customer-no-border-table" label="歌曲列表" name="first">
          <album-song :search="search" :songs="songs" :id="id" />
        </el-tab-pane>
        <el-tab-pane :label="getComment" name="second">
          <album-comment :commentCount="getCommentCount" :id="id" />
        </el-tab-pane>
        <el-tab-pane label="专辑详情" name="third">
          <div class="desc-title">专辑介绍</div>
          <div class="desc-content">{{album.description || "暂无介绍"}}</div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <!--歌曲列表结束 -->
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { getalbumAPI } from "@/api/album.js";
import albumSong from "./components/album-song.vue";
import albumComment from "./components/album-comment.vue";

export default {
  name: "album",
  //import引入的组件需要注入到对象中才能使用
  components: { albumSong, albumComment },
  props: {
    id: {
      require: true,
    },
  },
  data() {
    //这里存放数据
    return {
      playlist: {},
      // id: "",
      activeName: "first",
      subscribers: {},
      search: "",
      album: {
        name: "",
      },
      songs: {},
      resourceState: true,
    };
  },
  //计算属性 类似于data概念
  computed: {
    getTransName() {
      if (this.album.transNames != undefined) {
        return "(" + this.album.transNames[0] + ")";
      }
      return "";
    },
    getComment: function () {
      if (this.album.info != undefined) {
        return "评论(" + this.album.info.commentCount + ")";
      }
      return "评论(" + 0 + ")";
    },
    getCommentCount() {
      if (this.album.info != undefined) {
        return this.album.info.commentCount;
      }
      return 0;
    },
    getArtistName() {
      if (this.album.artist != undefined) {
        return this.album.artist.name;
      }
      return "";
    },
    // 格式化时间
    getTime: function () {
      let time = new Date(this.album.publishTime);
      let year = time.getFullYear();
      let month = time.getMonth() + 1;
      let day = time.getDate();
      // console.log(time.getFullYear() + "-" + time.getMonth() + "-" + time.getDate());
      if (time.getMonth() < 10) {
        month = "0" + month;
      }
      if (time.getDate() < 10) {
        day = "0" + day;
      }
      return year + "-" + month + "-" + day;
    },
  },
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    handleClick() {},
    // 添加音乐到播放列表
    addmusic() {
      this.$store.commit("addMusictoMusiclist", this.id);
    },
    // 播放当前歌单
    playnowMusiclist() {
      this.$store.commit("playnowMusiclist", this.id);
    },
    //歌单详情信息
    async getalbumInfo() {
      try {
        const { data } = await getalbumAPI(this.id);
        // console.log(data, "获得专辑");
        this.songs = data.songs;
        this.album = data.album;
        document.title = this.album.name + " - 专辑";
      } catch (error) {
        console.log(error + "获取专辑详情失败");
      }
    },
    // async setintroduction() {
    //   let detail = await getalbumdetailAPI(this.id);
    //   console.log(detail, "获得专辑详情");
    // },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    // this.id = this.$route.query.id;
    this.getalbumInfo();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style scoped lang="less">
.playlist-detail {
  //为音乐播放器留位置
  padding-bottom: 80px;
  .playlist-info {
    position: relative;
    padding-top: 30px;
    margin: 0 auto;
    width: 1200px;
    display: flex;
    height: 100%;
    margin-bottom: 30px;
    .pic {
      flex-shrink: 0;
      width: 200px;
      height: 200px;
      border-radius: 5px;
      border: 1px solid rgb(133, 133, 133);
      overflow: hidden;
      img {
        width: 200px;
        height: 200px;
      }
    }
    .info {
      margin-left: 30px;
      .btn-group {
        margin-top: 10px;
        margin-bottom: 10px;
        .icon-palyer-start-01 {
          font-size: 14px;
        }
      }

      .time {
        font-size: 15px;
        color: rgb(75, 75, 75);
        margin-top: 13px;
        margin-left: 6px;
        cursor: default;
      }
      .title {
        font-size: 24px;
        font-weight: 600;
        margin-bottom: 10px;
        color: #373737;
        display: flex;
        .icon-title {
          cursor: default;
          font-weight: 520;
          display: inline-block;
          font-size: 17px;
          color: #44aaf8;
          padding: 2px 5px 2px 5px;
          border: 1px solid #44aaf8;
          border-radius: 5px;
          margin-right: 10px;
        }
        .transName {
          color: #9f9f9f;
        }
      }
      .author {
        margin-left: 6px;
        font-size: 15px;
        color: rgb(65, 65, 65);
        margin-bottom: 6px;
        margin-top: 6px;
        cursor: default;
        .name {
          cursor: pointer;
          color: #507daf;
          display: inline-block;
        }
        .name:hover {
          color: #0b58b0;
        }
      }
    }
  }
  .desc-title {
    font-weight: 600;
    color: #373737;
    line-height: 30px;
  }
  .desc-content {
    color: #676767;
    white-space: pre-wrap;
    line-height: 30px;
  }
  .playlist-music {
    width: 1200px;
    margin: 0 auto;
  }
  .input-search {
    position: absolute;
    right: 0;
    bottom: -50px;
    margin-top: 30px;
    z-index: 1000;
  }
  // 去除elmentuitab自带的边框
  /*去掉表格单元格边框*/
  :deep(.customer-no-border-table th) {
    border: none;
  }
  /deep/ .customer-no-border-table td,
  /deep/ .customer-no-border-table th.is-leaf {
    border: none;
  }
  /*表格最外边框*/
  /deep/ .customer-no-border-table .el-table--border,
  .el-table--group {
    border: none;
  }
  /*头部边框*/
  /deep/ .customer-no-border-table thead tr th.is-leaf {
    border: 0px solid #ebeef5;
    border-right: none;
  }
  /deep/ .customer-no-border-table thead tr th:nth-last-of-type(2) {
    border-right: 0px solid #ebeef5;
  }
  /*表格最外层边框-底部边框*/
  /deep/ .customer-no-border-table .el-table--border::after,
  /deep/ .customer-no-border-table .el-table--group::after {
    width: 0;
  }
  /deep/ .customer-no-border-table::before {
    width: 0;
  }
  /deep/ .customer-no-border-table .el-table__fixed-right::before,
  .el-table__fixed::before {
    width: 0;
  }
  /deep/ .customer-no-border-table .el-table__header tr th {
    background: #fff;
    color: #333333;
    padding: 3px;
    font-weight: 550;
    height: 36px;
    border: 0px;
    font-size: 15px;
  }
  /deep/.el-table::before {
    height: 0;
  }
}
/deep/ .user-info {
  text-decoration: none;
  color: #467de4;
}
/deep/ .user-info:hover {
  text-decoration: none;
  color: #3c5d9b;
}
</style>
